package com.miku.ai.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.miku.ai.model.entity.UserAnswer;
import com.miku.ai.model.statistic.AppAnswerCountDto;
import com.miku.ai.model.statistic.AppAnswerResultCountDto;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author ThinkBook
* @description 针对表【user_answer(用户答题记录)】的数据库操作Mapper
* @createDate 2024-10-08 15:37:32
* @Entity com.miku.ai.model.entity.UserAnswer
*/
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {

    /**
     * 查询每个应用答题人数
     * @return
     */
    @Select("select appId,COUNT(userId) as answerCount from user_answer group by appId order by answerCount desc limit 10")
    List<AppAnswerCountDto> doAppAnswerCount();

    /**
     * 查询每个应用答题结果数量
     * @return
     */

    @Select("select resultName, count(resultName) as resultCount from user_answer " +
            "where appId = #{appId} group by resultName order by resultCount desc")
    List<AppAnswerResultCountDto> doAppAnswerResultCount(Long appId);
}




